perf: increase job concurrency, add channel routing and identity keys#151
perf: increase job concurrency, add channel routing and identity keys#151gonzalesedwin1123 merged 3 commits into19.0from
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements bulk membership creation for programs and cycles using raw SQL to improve performance and handle duplicates. It introduces context flags to skip expensive statistics recomputations during bulk operations, adds explicit refresh methods, refactors asynchronous job handling with specific channels and identity keys, and updates queue configurations. Feedback focuses on ensuring UTC timestamps in raw SQL queries and correcting a missing return value to align with method documentation.
| values = [] | ||
| params = [] | ||
| for v in batch: | ||
| values.append("(%s, %s, %s, %s, %s, %s, now(), now())") |
There was a problem hiding this comment.
When using raw SQL in Odoo, it is recommended to explicitly use (now() at time zone 'utc') for create_date and write_date. This ensures that the timestamps are stored in UTC regardless of the database session's timezone configuration, adhering to Odoo's standard data storage practices.
| values.append("(%s, %s, %s, %s, %s, %s, now(), now())") | |
| values.append("(%s, %s, %s, %s, %s, %s, now() at time zone 'utc', now() at time zone 'utc')") |
| for v in batch: | ||
| state = v.get("state", "draft") | ||
| enrollment_date = now if state == "enrolled" else None | ||
| values.append("(%s, %s, %s, %s, %s, %s, now(), now())") |
There was a problem hiding this comment.
When using raw SQL in Odoo, it is recommended to explicitly use (now() at time zone 'utc') for create_date and write_date. This ensures that the timestamps are stored in UTC regardless of the database session's timezone configuration, adhering to Odoo's standard data storage practices.
| values.append("(%s, %s, %s, %s, %s, %s, now(), now())") | |
| values.append("(%s, %s, %s, %s, %s, %s, now() at time zone 'utc', now() at time zone 'utc')") |
| } | ||
| for partner_id in beneficiaries | ||
| ] | ||
| self.env["spp.cycle.membership"].bulk_create_memberships(vals_list, skip_duplicates=True) |
There was a problem hiding this comment.
The method _add_beneficiaries is missing a return statement. According to its docstring, it should return an integer representing the count of inserted members. Returning the result of bulk_create_memberships will satisfy this requirement.
| self.env["spp.cycle.membership"].bulk_create_memberships(vals_list, skip_duplicates=True) | |
| return self.env["spp.cycle.membership"].bulk_create_memberships(vals_list, skip_duplicates=True) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 19.0 #151 +/- ##
==========================================
+ Coverage 71.36% 71.45% +0.09%
==========================================
Files 932 932
Lines 54792 54794 +2
==========================================
+ Hits 39101 39154 +53
+ Misses 15691 15640 -51
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Increase parallel-safe channel limits from 1 to 4 (cycle, eligibility_manager, program_manager) now that INSERT ON CONFLICT makes these operations safe for concurrent execution. Add two serial channels: - entitlement_approval (limit=1): fund balance tracking must be serial - statistics_refresh (limit=1): avoid concurrent refresh storms Route entitlement approval/validation jobs to entitlement_approval channel. Route all completion handlers (mark_*_as_done) to statistics_refresh channel. Add identity_key to all async dispatch methods to prevent duplicate job submission when users double-click action buttons.
38bc517 to
0cacf62
Compare
Summary
entitlement_approvalchannel (limit=1) for fund balance tracking that must remain serialstatistics_refreshchannel (limit=1) to prevent concurrent refresh storms from completion handlersidentity_keyto all async job dispatchers to prevent duplicate job submission on double-clickChanges
queue_data.xml: Bump cycle/eligibility/program channels to limit=4; add entitlement_approval and statistics_refresh channels at limit=1cycle_manager_base.py: Add identity_key to check_eligibility, prepare_entitlements, add_beneficiaries dispatchers; route mark_*_as_done to statistics_refreshprogram_manager.py: Add identity_key to enroll_eligible dispatcher; route mark_enroll_eligible_as_done to statistics_refresheligibility_manager.py: Add identity_key to import_registrants dispatcher; route mark_import_as_done to statistics_refreshentitlement_manager_base.py: Route set_pending_validation, validate, cancel entitlements to entitlement_approval channelentitlement_manager_cash.py: Route validate_entitlements to entitlement_approval channelentitlement_manager_inkind.py: Route set_pending_validation and validate_entitlements to entitlement_approval channelContext
Phase 9 of 9 in the
spp_programsperformance optimization effort. Rebased on current 19.0. Version bumped to 19.0.2.0.10.Test plan
./scripts/test_single_module.sh spp_programs— 615 tests, 0 failurespre-commit run --files <changed_files>— all checks passODOO_INIT_MODULES=spp_programs docker compose --profile ui up -d